package com.miaomi.Controller;

import java.util.*;

import com.miaomi.Bean.Tel_sys;
import com.miaomi.Service.impl.TelephoneServiceImpl;

public class uiTel {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("-------------------------------------------------通讯录管理系统------------------------------------------------------");
            System.out.println("1.添加联系人   2.删除联系人     3.修改联系人        4.查询所有信息     5.根据姓名查询信息     6.根据ID查询信息      0.退出系统" );
            System.out.println("请您输入想要进行的功能：");
            int key = scanner.nextInt();
            TelephoneServiceImpl telephoneService = new TelephoneServiceImpl();
            switch (key){
                case 1:
                    System.out.println("请您输入姓名：");
                    String name = scanner.next();
                    System.out.println("请你输入年纪：");
                    int age = scanner.nextInt();
                    System.out.println("请您输入性别：");
                    String gender = scanner.next();
                    System.out.println("请您输入电话号码：");
                    String tel = scanner.next();
                    System.out.println("请您输入QQ号：");
                    String qq = scanner.next();
                    System.out.println("请您输入地址：");
                    String addr = scanner.next();
                    boolean b = telephoneService.InsertTel(new Tel_sys(null, name, age, gender, qq, tel, addr));
                    if (b == true){
                        System.out.println("添加成功");
                    }else {
                        System.out.println("添加失败");
                    }
                    break;

                case 2:
                    System.out.println("请输入ID进行删除：");
                    int id = scanner.nextInt();
                    if (telephoneService.DeleteTel(id) == true) {
                        System.out.println("删除成功");
                    }else {
                        System.out.println("删除失败");
                    }
                    break;

                case 3:
                    System.out.println("请根据ID进行修改");
                    int id1 = scanner.nextInt();
                    System.out.println("接下来请输入您要修改的信息：");
                    System.out.println("请您输入姓名：");
                    String name1 = scanner.next();
                    System.out.println("请你输入年纪：");
                    int age1 = scanner.nextInt();
                    System.out.println("请您输入性别：");
                    String gender1 = scanner.next();
                    System.out.println("请您输入电话号码：");
                    String tel1 = scanner.next();
                    System.out.println("请您输入QQ号：");
                    String qq1 = scanner.next();
                    System.out.println("请您输入地址：");
                    String addr1 = scanner.next();
                    if (telephoneService.UpdateTel(new Tel_sys(id1,name1,age1,gender1,qq1,tel1,addr1)) == true) {
                        System.out.println("修改成功");
                    }else {
                        System.out.println("修改失败");
                    }
                    break;

                case 4:
                    List<Tel_sys> telSys = telephoneService.SelectAll();
                    telSys.stream()
                            .forEach(System.out::println);
                    System.out.println("查询成功！");
                    break;

                case 5:
                    System.out.println("请输入您想要查询的信息的联系人姓名:");
                    String name2 = scanner.next();
                    List<Tel_sys> telSys1 = telephoneService.SelectName(name2);
                    telSys1.stream()
                            .forEach(System.out::println);
                    System.out.println("查询成功！");
                    break;

                case 6:
                    System.out.println("请输入您想要查询的信息的联系人ID:");
                    int id2 = scanner.nextInt();
                    List<Tel_sys> telSys2 = telephoneService.SelectId(id2);
                    telSys2.stream()
                            .forEach(System.out::println);
                    System.out.println("查询成功！");
                    break;
                case 0:
                    System.out.println("退出成功，感谢您的使用！");
                    return ;
            }
        }
    }
}
